﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ST.Core.Util
{
    public static class IdUtil
    {
        private static readonly IdWorker _idWorker = new IdWorker(1, 1);

        /// <summary>
        /// 生成下一个唯一ID
        /// </summary>
        /// <returns>返回一个唯一的long型ID</returns>
        public static long NextId()
        {
            return _idWorker.NextId();
        }


        /// <summary>
        /// 将日期转换为ID，仅保留时间戳部分
        /// </summary>
        /// <param name="dateTime">要转换的日期时间</param>
        /// <returns>仅包含时间戳部分的ID</returns>
        public static long ConvertDateTimeToId(DateTime dateTime)
        {
            return _idWorker.ConvertDateTimeToId(dateTime);
        }

        /// <summary>
        /// 将ID转换为时间
        /// </summary>
        /// <param name="id">要转换的ID</param>
        /// <returns>转换后的时间</returns>
        public static DateTime ConvertIdToDateTime(long id)
        {
            return _idWorker.ConvertIdToDateTime(id);
        }
    }
}
